import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/lib_runtime/extension/widget/widget_wrapper.dart';
import 'package:ones/ui.dart';
import 'package:provider/provider.dart';

import '../../../../lib_basemodel/chat_room/habibi-msg/hb_rtm_msg.dart';
import '../../../../lib_basemodel/chat_room/kh_chat_room_seat_model.dart';
import '../../../../lib_baseview/lib_baseview.dart';
import '../../../../lib_baseview/theme/jr.dart';
import '../../../../lib_baseview/utils/constant/text_styles.dart';
import '../../../../lib_baseview/utils/screen_utils.dart';
import '../../../../lib_rtc/rtc/rtc_manager.dart';
import '../../../../m_main/any_im_page/conversation_controller.dart';
import '../../../../resource/language/generated/l10n.dart';
import '../../input/item_style.dart';
import '../../input/message_input_overlay.dart';
import '../../interface/room_page_model.dart';
import '../../msg/room_msg.dart';
import '../../socket/room_builder/room_msg_list.dart';
import '../../template/apply_mic_list/apply_mic_list_page.dart';
import '../../template/line_list/on_line_list_widget.dart';
import '../../template/menu/menu_play_dialog.dart';
import '../../template/mic_seat/mic_seat_widget.dart';
import '../../template/music/widget/float_music_playing_bar.dart';
import '../../template/music/widget/room_lyric_widget.dart';
import '../../template/tools/room_main_tool_page.dart';
import '../../template/topbar/chat_room_tap_bar.dart';
import 'gift_display.dart';

mixin RoomPageMixin {
  /// 底部栏icon间距
  static const double bottomIconPadding = 10;

  static const String defaultBgAsset = 'assets/images/room/room_bg_image.png';

  RoomPageModel get model;

  BuildContext get context;

  Widget get body => Stack(
        children: stackWidgets,
      );

  Widget get roomColumn => SafeArea(
        bottom: false,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ...columnWidgets,
            Container(
              height: ScreenUtils.ins.bottomBarHeight,
            )
          ],
        ),
      );

  List<Widget> get stackWidgets => [
        roomBg,
        roomColumn,
        // if (Get.isRegistered<RoomMusicCenterController>()) lyric,
        // giftAnimation,
        // joinAnimation,
      ];

  List<Widget> get columnWidgets => [
        roomHeader,
        topEntry,
        roomMics,
        // clubOnlineList,
        msgArea,
        // musicBar,
        // roomBottom,
        roomBottom,
      ];

  /// 默认背景图
  Widget get defaultBg => Image.asset(
        defaultBgAsset,
        width: double.infinity,
        height: double.infinity,
        fit: BoxFit.fill,
      );

  /// 房间背景
  Widget get roomBg => defaultBg;

  // Widget get roomBg => Container(
  //       width: ScreenUtil().screenWidth,
  //       height: ScreenUtil().screenHeight,
  //       color: const Color(0xFF120037),
  //     );

  /// 标题栏 注意：这里不能添加 const关键字，否则房间标题不会更新
  Widget get roomHeader => Padding(
        padding: EdgeInsets.only(bottom: 8),
        child: ChatRoomTopBar(),
      );

  /// 顶部活动栏
  Widget get topEntry => Padding(
        padding: const EdgeInsets.only(bottom: 8, top: 18),
        child: Row(
          children: [
            heatActivityWidget,
            const Spacer(),
            heatActivityRigthWidget,
            // noticeEntry,
            // const Spacer(),
            // gameEntry,
            // roomDrawerEntry,
          ],
        ),
      );

  /// 顶部右侧头像、房间人数
  /// 注意：这里房间的真实人数为0
  /// 这里的列表应该是没有数据的，所以这里房间麦位上的人数放在这里
  Widget get heatActivityRigthWidget {
    return Consumer<RoomPageModel>(builder: (context, model, child) {
      // 过滤 data 不为 null 的对象
      final micListUser = model.roomEnterModel.micList
          ?.where((obj) => obj?.micUser != null) // 过滤条件
          .toList(); // 转换为列表

      return Container(
        child: Row(
          children: [
            SizedBox(
              height: 28, // 设置固定高度
              width: micListUser?.length != null
                  ? (micListUser!.length > 5 ? 5 : micListUser.length) *
                      (28 + 3)
                  : 0, // 根据子项数量计算宽度，最多按 5 个计算
              child: GridView.builder(
                scrollDirection: Axis.horizontal,
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 1,
                  childAspectRatio: 1.0,
                  crossAxisSpacing: 5, // 设置交叉轴方向（垂直方向）的间距为 5
                  mainAxisSpacing: 5, // 设置主轴方向（水平方向）的间距为 5
                ),
                itemCount: micListUser?.length,
                itemBuilder: (context, index) {
                  KHChatRoomSeatModel? micModel = micListUser?[index];
                  return micModel?.micUser?.headPortraitsUrl != null
                      ? Row(
                          children: [
                            JR
                                .img(micModel?.micUser!.headPortraitsUrl ?? '',
                                    width: 28, height: 28)
                                .corner(radius: 28 / 2.0),
                          ],
                        )
                      : const SizedBox.shrink();
                },
              ),
            ),
            const SizedBox(width: 3),
            JR.img(
              'room/room_right_arrow_icon.png',
              width: 16,
              height: 16,
              fit: BoxFit.contain,
            ),
            const SizedBox(width: 3),
            Stack(
              alignment: AlignmentDirectional.center,
              children: [
                Image.asset(
                  "assets/images/room/room_people_num.png",
                  width: 32,
                  height: 32,
                  fit: BoxFit.contain,
                ),
                Positioned(
                  bottom: 0,
                  child:
                      (model.roomEnterModel.roomBaseInfoModel?.realPeople ?? 0)
                          .toString()
                          .text(color: const Color(0xFFFFFFFF), fontSize: 10),
                ),
              ],
            ),
            const SizedBox(width: 15),
          ],
        ).onClick(() {
          // showModalBottomSheet(
          //   context: context,
          //   backgroundColor: Colors.white,
          //   builder: (BuildContext context) {
          //     return onlineList(context, micListUser);
          //   },
          // );
        }),
      );
    });
  }

  /// 在线列表
  onlineList(BuildContext context, List<KHChatRoomSeatModel?>? micList) {
    Future.delayed(Duration.zero, () {
      showModalBottomSheet(
        context: context,
        backgroundColor: Colors.white,
        builder: (BuildContext context) {
          return OnLineListWidget(
            micList: micList,
          );
        },
      );
    });
  }

  /// 百万俱乐部在线人数组件
  Widget get clubOnlineList {
    // if (model.channel?.roomTypeObj.type != RoomType.MILLION_CLUB) {
    //   return const SizedBox();
    // }
    return Column(
      children: [
        const SizedBox(
          height: 19,
        ),
        Container(
          height: 42,
          margin: const EdgeInsets.symmetric(horizontal: 16),
          padding: const EdgeInsets.symmetric(horizontal: 10),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(12.0),
            color: const Color.fromRGBO(223, 214, 255, 0.09),
          ),
          // color: Colors.red,
          child: Row(
            children: [
              // Expanded(
              //   child: DFListView(
              //     scrollDirection: Axis.horizontal,
              //     shrinkWrap: true,
              //     showEmpty: false,
              //     datas: model.channel!.offMicUser,
              //     builder: (ctx, index, OffMicUser model) {
              //       SimpleChannelUser userModel = SimpleChannelUser.create()
              //         ..id = model.uid
              //         ..avatar = model.icon;
              //       return millionClubMemberShipItem(userModel);
              //     },
              //   ),
              // ),
              const Text('DFListView'),
              const SizedBox(
                width: 10,
              ),
              Column(
                // crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    T.current.mic_down,
                    style: const TextStyle(
                      color: Color(0xffFFFFFF),
                      fontSize: 8,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  Text(
                    // T.current!.some_people(model.channel!.offMicUser.length),
                    'T.current!.some_people',
                    style: TextStyle(
                      color: const Color(0xffFFFFFF).withOpacity(0.6),
                      fontSize: 8,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ],
    );
  }

  /// 麦位
  Widget get roomMics => Center(child: MicSeatWidget());

  List<Widget> get msgAreaWidgets => [
        msgList,
        PositionedDirectional(
          bottom: 2,
          child: ValueListenableBuilder<int>(
            valueListenable: model.barrageListModel.unReadMsgNum,
            builder: (BuildContext c, int value, Widget? child) {
              if (value <= 0) {
                return SizedBox.shrink();
              }
              return GestureDetector(
                onTap: () {
                  // model.barrageListModel.jumpBottom();
                },
                child: Container(
                  height: 30,
                  padding: EdgeInsets.symmetric(horizontal: 20),
                  alignment: Alignment.center,
                  decoration: ShapeDecoration(
                      shape: StadiumBorder(),
                      gradient: LinearGradient(colors: JR.color.brandGradient)),
                  child: Text('$value new message ⇣',
                      style: JRTextStyles.styleFont12W400
                          .copyWith(color: Colors.white)),
                ),
              );
            },
          ),
        )
      ];

  /// 公屏区域
  Widget get msgArea => Expanded(
        child: Stack(
          alignment: Alignment.topCenter,
          children: msgAreaWidgets,
        ),
      );

  /// 公屏
  Widget get msgList => Container(
        padding: const EdgeInsets.only(top: 3),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: RoomMsgList(model: model.barrageListModel),
            ),
            // Container(
            //   decoration: BoxDecoration(
            //       border: Border.all(
            //     width: 1.0,
            //     color: Colors.red,
            //   )),
            //   child: Row(
            //     crossAxisAlignment: CrossAxisAlignment.end,
            //     mainAxisAlignment: MainAxisAlignment.spaceAround,
            //     children: [
            //       Column(
            //         crossAxisAlignment: CrossAxisAlignment.end,
            //         children: [
            //           // _menuEntryWidget(),
            //           const Spacer(),
            //           testEntry,
            //         ],
            //       ),
            //     ],
            //   ),
            // ),

            const SizedBox(
              width: 10,
            ),
          ],
        ),
      );

  /// 音乐控制条
  Widget get musicBar => Padding(
        padding: const EdgeInsetsDirectional.only(start: 22, bottom: 10),
        child: FloatMusicPlayingBar(),
      );

  /// 礼物动画
  Widget get giftAnimation => const GiftDisplay();

  /// 进房动画
  // Widget get joinAnimation => model.joinUserList.isNotEmpty
  //     ? AnimatedBuilder(
  //         animation: model.userJoinAnimationController!,
  //         builder: (context, child) {
  //           //每次调用builder，内部所有组件都会重新渲染，注意考虑优化性能
  //           return PositionedDirectional(
  //             end: ((model.animation?.value ?? 0) * 247.0) - 247.0,
  //             top: 458,
  //             child: child!,
  //           );
  //         },
  //         //动画执行过程中，不需要变化的部分可以传给AnimatedBuilder，
  //         // 每次builder回调时候会再传出来，这样就避免了child部分的重新渲染
  //         child: const IgnorePointer(
  //             child: UserJoinAnimationWidget(
  //                 /*user: model.joinUserList.first.user */)),
  //       )
  //     : const SizedBox();

  /// 进房动画
  Widget get joinAnimation => const Text('进房joinAnimation动画');

  /// sud游戏入口
  Widget get gameEntry => const SizedBox();

  /// 火爆大厅房间列表
  Widget get hotHallEntry {
    return CupertinoButton(
      onPressed: () {
        Scaffold.of(context).openEndDrawer();
      },
      minSize: 0,
      padding: EdgeInsets.zero,
      child: Stack(
        alignment: Alignment.topRight,
        children: [
          Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const SizedBox(
                height: 3,
              ),
              Container(
                width: 42,
                height: 42,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(21),
                  gradient: const LinearGradient(
                    colors: [
                      Color(0xFF806DFF),
                      Color(0xFF693DFF),
                      Color(0xFFA473FC)
                    ],
                    stops: [0, 0.468, 1],
                  ),
                ),
                alignment: Alignment.center,
                child: Image.asset(
                  "assets/images/ic_room_entry.png",
                  width: 17,
                  height: 17,
                  fit: BoxFit.fill,
                ),
              ),
              const SizedBox(
                height: 4,
              ),
              Text(
                T.current.room,
                style: const TextStyle(
                  fontSize: 13,
                  color: Colors.white,
                  fontWeight: FontWeight.w500,
                ),
                strutStyle: const StrutStyle(
                  height: 1,
                  forceStrutHeight: true,
                ),
              )
            ],
          ),
        ],
      ),
    );
  }

  ///测试按钮
  Widget get testEntry {
    // if (GlobalConfig.isDebug) {
    return CupertinoButton(
      onPressed: () {
        model.sendUserInputTextMessage(
          '测试发送公屏消息',
          itemStyle: ItemStyle.text,
        );

        // CpPairChange info = CpPairChange.create()
        //   ..fromNickName = '测试姓名1'
        //   ..toNickName = '测试姓名2'
        //   ..desc = '甜蜜暴击，成功心动反转';
        // eventCenter.emit(Event(EventConstant.cpChooseChanged, data: info));
      },
      minSize: 0,
      padding: const EdgeInsets.only(bottom: 10),
      child: const Text(
        "测试按钮",
        style: TextStyle(
          fontSize: 13,
          color: Colors.white,
          fontWeight: FontWeight.w500,
        ),
        strutStyle: StrutStyle(
          height: 1,
          forceStrutHeight: true,
        ),
      ),
    );
    // }
    // return const SizedBox.shrink();
  }

  // Widget _gameEntryWidget() {
  //   return GestureDetector(
  //     onTap: () async {
  //       // GameSelectDialog.show(context);
  //     },
  //     child: image('room/room_setting/room_edit.png', width: 60, height: 60),
  //   );
  // }

  // Widget _menuEntryWidget() {
  //   return GestureDetector(
  //     onTap: () async {
  //       MenuPlayDialog.show(context);
  //     },
  //     child: image('room/room_bottom_aplay_mic.png', width: 60, height: 60),
  //   );
  // }

  Widget get roomBottom => Padding(
        padding: const EdgeInsets.only(bottom: 10, left: 15, right: 15),
        child: Row(
          children: [
            voiceIcon,
            const SizedBox(width: 11),
            // joinOrMute,
            // manageMic,
            // testVoice,
            msgIcon,
            const SizedBox(width: 15),
            roomApplyWheatIcon,
            const SizedBox(width: 13),
            roomSetIcon,
            const SizedBox(width: 17),
            giftIcon,
            roomGameIcon,
            // imIcon,
            // toolsIcon,
          ],
        ),
      );

  /// onPressed：回调
  /// iconPath：本地图片地址/网络图片地址、
  /// width：宽度
  /// height：高度
  /// assembly：是否是组合视图
  Widget buildBottomItem(VoidCallback onPressed, String iconPath,
          {double? width = 36, double? height = 36, bool? assembly = false}) =>
      CupertinoButton(
        onPressed: onPressed,
        minSize: 0,
        padding: EdgeInsets.zero,
        child: (assembly ?? false)
            ? Stack(
                alignment: AlignmentDirectional.center,
                children: [
                  JR
                      .img(iconPath,
                          width: (width ?? 0) - 3,
                          height: (height ?? 0) - 3,
                          fit: BoxFit.contain)
                      .corner(radius: ((width ?? 0) - 3) / 2.0),
                  JR.img('room/room_manager_bg_circle.png',
                      width: width, height: height, fit: BoxFit.contain),
                ],
              )
            : JR.img(iconPath,
                width: width, height: height, fit: BoxFit.fitWidth),
      );

  Widget buildBottomMic(VoidCallback onPressed, String title, {int count = 0}) {
    return Stack(
      children: [
        Padding(
          padding: const EdgeInsets.only(right: bottomIconPadding),
          child: CupertinoButton(
            onPressed: onPressed,
            minSize: 0,
            padding: EdgeInsets.zero,
            child: Container(
              height: 30,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(15),
                color: const Color(0x14FFFFFF),
              ),
              padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
              child: Text(
                title,
                style: const TextStyle(
                    fontSize: 11,
                    color: Colors.white,
                    fontWeight: FontWeight.w500),
                strutStyle: const StrutStyle(height: 1, forceStrutHeight: true),
              ),
            ),
          ),
        ),
        if (count > 0)
          PositionedDirectional(
            top: 0,
            end: 0,
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 4),
              decoration: const ShapeDecoration(
                  shape: StadiumBorder(), color: Colors.red),
              child: Text(
                '$count',
                style: const TextStyle(fontSize: 9, color: Colors.white),
              ),
            ),
          ),
      ],
    );
  }

  /// 开、闭麦按钮
  // Widget get muteIcon => Padding(
  //       padding: const EdgeInsets.only(right: bottomIconPadding),
  //       child: buildBottomItem(() {
  //         model.changeMicStatus();
  //       },
  //           model.isCurrUserMicOn
  //               ? "assets/images/ic_mic_on.png"
  //               : "assets/images/ic_mic_off.png"),
  //     );

  // bool get needShowManageMic =>
  //     (model.currentRoomUserType == RtcUserRole.Owner ||
  //         model.currentRoomUserType == RtcUserRole.Manager ||
  //         model.currentRoomUserType == RtcUserRole.Receptionist) &&
  //     model.channel?.freePub == false;

  bool get needShowManageMic => false;

  // bool get needShowTestMic => (model.onMic &&
  //     model.channel?.roomTypeObj.type == RoomType.HOT_HALL &&
  //     model.currentMicSeatPosition >= 3);
  bool get needShowTestMic => true;

  /// 排麦按钮，管理员角色才显示
  Widget get manageMic {
    if (!needShowManageMic) return const SizedBox();
    return buildBottomMic(
        () => model.openMicWaitingListPage(context), T.current.wait_mic,
        count: /*model.channel?.waitCount ?? 0 */ 0);
  }

  /// 试音按钮
  Widget get testVoice {
    if (needShowTestMic) {
      return InkWell(
        onTap: () {
          if (model.inAudition) {
            // model.stopAuditionVoice(model.currUser?.id);
          } else {
            // model.startAuditionVoice(model.currUser?.id);
          }
        },
        child: Container(
          height: 30,
          margin: const EdgeInsetsDirectional.only(end: bottomIconPadding),
          padding: const EdgeInsetsDirectional.only(start: 10, end: 10),
          alignment: Alignment.center,
          decoration: const ShapeDecoration(
            shape: StadiumBorder(),
            color: Color(0xFFFFD400),
          ),
          child: Text(
            model.inAudition ? T.current.ending : T.current.test_voice,
            style: const TextStyle(
                fontSize: 11, color: Colors.black, fontWeight: FontWeight.w500),
            strutStyle: const StrutStyle(height: 1, forceStrutHeight: true),
          ),
        ),
      );
    }
    return const SizedBox();
  }

  /// 礼物打赏
  Widget get giftIcon {
    return Padding(
      padding: const EdgeInsetsDirectional.only(end: bottomIconPadding),
      child: buildBottomItem(() {
        model.clickRoomGift(context);
      }, "assets/images/room/room_bottom_icon.png"),
    );
  }

  /// 声音
  Widget get voiceIcon {
    return buildBottomItem(
      () {
        model.changeMicStatus();

        // /// 麦克风是否开启
        // bool _isMicOn = false;
        // bool get isMicOn => _isMicOn;
        // set isMicOn(bool value) {
        //   _isMicOn = value;
        // }
      },
      model.onMic
          ? "assets/images/room/room_tool_bar_mic_on.png"
          : "assets/images/room/room_tool_bar_mic_off.png",
      width: 30,
      height: 30,
    );
  }

  /// 房间玩法
  Widget get roomGameIcon {
    return buildBottomItem(() {
      model.clickRoomGift(context);
    }, "assets/images/room/room_bottom_game_icon.png");
  }

  /// 申请上麦
  Widget get roomApplyWheatIcon {
    //  "assets/images/room/room_bottom_aplay_mic.png" 已上麦
    return buildBottomItem(() {
      model.clickRoomGift(context);
    }, "assets/images/room/room_bottom_aplay_mic.png");
  }

  /// 设置
  Widget get roomSetIcon {
    return Consumer<RoomPageModel>(
      builder: (context, provider, _) {
        final showApplyMic = provider.applyMicList?.isNotEmpty;

        // applyMicList
        String? currHeadStr;
        HbRtmMsg? tmpChatModel;
        if (showApplyMic ?? false) {
          tmpChatModel = provider.applyMicList?.last;
          currHeadStr = tmpChatModel?.msg?.headPortraitsUrl;
        }

        return buildBottomItem(() {
          if (showApplyMic ?? false) {
            showModalBottomSheet(
              context: context,
              backgroundColor: Colors.white,
              builder: (BuildContext context) {
                return ApplyMicListPage(
                  applyMicList: provider.applyMicList,
                  onItemSelected: (index) {
                    model.holdUpMic(index);
                  },
                );
              },
            );
          } else {
            // MenuPlayDialog.show(context,roomOwner:);
            final bool? romOwner =
                provider.roomEnterModel.chatRoomModel?.userInfo?.roomRole == 1;
            // MenuPlayDialog.show(
            //   context,
            //   owner: romOwner,
            // );
            // MenuPlayDialog(content, owner: romOwner);
            MenuPlayDialog.show(context, romOwner);
          }
        }, currHeadStr ?? "assets/images/room/room_bottom_voice_icon.png",
            assembly: showApplyMic, width: 32, height: 32);
      },
    );
  }

  /// 发公屏
  Widget get msgIcon {
    return Expanded(
      child: Container(
        // color: Colors.red,
        child: GestureDetector(
          onTap: () {
            _sendMsgAction();
          },
          child: Container(
            padding: const EdgeInsets.only(left: 7, right: 0),
            height: 30,
            width: 112,
            // margin: const EdgeInsets.only(right: bottomIconPadding),
            decoration: const ShapeDecoration(
                shape: StadiumBorder(), color: Color(0x14FFFFFF)),
            alignment: AlignmentDirectional.centerStart,
            child: Row(
              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  onTap: () {
                    _sendMsgAction();
                  },
                  child: Container(
                      color: Colors.transparent,
                      child: Stack(
                        alignment: AlignmentDirectional.center,
                        children: [
                          image('room/room_bottom_hi_icon.png',
                              width: 22, height: 22),
                          'Hi~'.text(
                              color: const Color(0xFF8A72FE), fontSize: 11)
                        ],
                      )),
                ),
                Container(
                  child: T.current.room17_say_something
                      .text(color: const Color(0xFFA5A1B9), fontSize: 12),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  ///showEmoji默认展示表情
  _sendMsgAction() {
    // showToast('T.current!.current_screen_closed');
    // if (model.channel?.freePublicChat != true) {
    //   showToast(T.current!.current_screen_closed);
    //   return;
    // }

    MessageInputOverlay.show(context, (
      input, {
      ItemStyle itemStyle = ItemStyle.text,
      String? extra,
      RoomMsg? quoteMsg,
    }) {
      model.sendUserInputTextMessage(input,
          itemStyle: itemStyle, extra: extra, quoteMsg: quoteMsg);
    });
  }

  /// 发私聊
  Widget get imIcon {
    return Padding(
      padding: const EdgeInsetsDirectional.only(end: bottomIconPadding),
      child: Stack(
        clipBehavior: Clip.none,
        children: [
          buildBottomItem(() {
            showChatMessage(context);
          }, "assets/images/ic_chat_room_person_im.png"),
          PositionedDirectional(
              top: 0,
              end: -3,
              child: GetBuilder<ConversationController>(
                  id: ConvUpdateIds.allUnReadCount,
                  builder: (logic) {
                    return Container(
                      // width: 15,
                      height: 11.5,
                      alignment: Alignment.center,
                      padding: const EdgeInsets.symmetric(
                        horizontal: 3,
                      ),
                      decoration: const BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.topLeft,
                          end: Alignment.bottomRight,
                          colors: [Color(0xFFFF7A7A), Color(0xFFFA4747)],
                        ),
                        // shape: BoxShape.circle,
                        borderRadius: BorderRadius.all(Radius.circular(5)),
                      ),
                      child: const Text(
                        "99+",
                        // logic.unReadCount > 99
                        //     ? "99+"
                        //     : "${logic.unReadCount}",
                        style: TextStyle(fontSize: 9, color: Colors.white),
                      ),
                    );
                  }))
        ],
      ),
    );
  }

  /// 弹出聊天框
  showChatMessage(BuildContext context) async {
    // ConversationPage.bottomShow(context);
    // await showModalBottomSheet(
    //   isScrollControlled: true, //添加该属性解决无法按预定高度弹起问题
    //   shape: const RoundedRectangleBorder(
    //     borderRadius: BorderRadius.only(
    //       topLeft: Radius.circular(24),
    //       topRight: Radius.circular(24),
    //     ),
    //   ),
    //   backgroundColor: Colors.transparent,
    //   context: context,
    //   builder: (context) {
    //     return ClipRRect(
    //       borderRadius: const BorderRadius.all(Radius.circular(24)),
    //       child: SizedBox(
    //           height: (ScreenUtils.screenH(context)) * 0.7,
    //           child: const MessagePage(
    //             pushType: PushType.show,
    //           )),
    //     );
    //   },
    // );
  }

  /// 房间工具
  Widget get toolsIcon {
    return buildBottomItem(() {
      showTools(context);
    }, "assets/images/ic_chat_room_tools.png");
  }

  Future<void> showTools(BuildContext context) async {
    await showModalBottomSheet(
        isScrollControlled: true,
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(24),
            topRight: Radius.circular(24),
          ),
        ),
        context: context,
        builder: (context) {
          return RoomToolWidget(context: context);
        });
  }

  Widget get lyric => const RoomLyricWidget();

  /// 百万俱乐部麦下人数列表
  // Widget millionClubMemberShipItem(SimpleChannelUser userModel) {
  //   return Row(
  //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //     children: [
  //       const SizedBox(
  //         width: 4,
  //       ),
  //       GestureDetector(
  //         onTap: () {
  //           RoomPersonalDataWidget.show(context, model.channel, userModel);
  //         },
  //         child: AvatarImage(
  //           placeholder: null,
  //           url: userModel.avatar,
  //           width: 30,
  //           height: 30,
  //           borderRadius: 15,
  //         ),
  //       ),
  //       const SizedBox(
  //         width: 4,
  //       ),
  //     ],
  //   );
  // }

  /// 左侧热度
  Widget get heatActivityWidget {
    // if (model.channel?.roomTypeObj.type != RoomType.MILLION_CLUB) {
    //   return Container();
    // }
    return CupertinoButton(
      onPressed: () {
        reportActivityListView(model);
        model.openProgramList(context);
      },
      minSize: 0,
      padding: EdgeInsets.zero,
      child: Container(
        height: 27,
        decoration: BoxDecoration(
          borderRadius: const BorderRadius.only(
            topRight: Radius.circular(27 / 2.0),
            bottomRight: Radius.circular(27 / 2.0),
          ),
          color: const Color(0xffFFA050).withAlpha((0.05 * 255).toInt()),
        ),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            const SizedBox(
              width: 12,
            ),
            Image.asset(
              "assets/images/room/room_trophy.png",
              width: 24,
              height: 24,
              fit: BoxFit.contain,
            ),
            // (model.channel?.program.startTime == "" &&
            //         model.channel?.program.topic == "")
            //     ? _defaultWidget()
            //     : _activeDetail(model),
            // _defaultWidget(),

            '999k'.text(
                color: const Color(0xFFFEB633),
                fontSize: 14,
                weight: TextFontWeight.medium),

            const SizedBox(
              width: 10,
            ),
          ],
        ),
      ),
    );
  }

  /// 数据上报
  reportActivityListView(RoomPageModel model) {
    // String role = "";
    // if (UserManager.instance.currentUser!.clubManager) {
    //   role = "club_admin";
    // } else if (UserManager.instance.currentUser!.job == Job.BOSS) {
    //   role = "boss";
    // } else {
    //   role = "GS";
    // }

    // Reporter.track(TrackEvent.activityListView, {
    //   "rid": model.channel!.channelId.toInt(),
    //   "role": role,
    // });
  }

  /// 公告
  Widget get noticeEntry {
    return Padding(
      padding: const EdgeInsets.only(left: 10.0),
      child: GestureDetector(
        onTap: () {
          // Get.bottomSheet(RoomNoticeBottomSheet(
          //   notice: model.channel?.notice ?? '',
          // ));

          Get.bottomSheet(const Text('RoomNoticeBottomSheet'));
        },
        child: Container(
          decoration: const ShapeDecoration(
            shape: StadiumBorder(),
            color: Color(0x14FFFFFF),
          ),
          height: 20,
          alignment: AlignmentDirectional.center,
          padding: const EdgeInsets.symmetric(horizontal: 8),
          child: Row(
            children: [
              JR.img('room_notice_icon.png', width: 14, height: 14),
              const SizedBox(
                width: 4,
              ),
              Text(
                T.current.bulletin,
                style: const TextStyle(
                    color: Colors.white,
                    fontSize: 10,
                    fontWeight: FontWeight.w400),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 房间百万俱乐部 左上角活动列表
  /// 活动小组件 （活动时间、活动名称）里面的内容显示的是活动列表相关内容
  Widget _activeDetail(RoomPageModel absModel) {
    return Consumer<RoomPageModel>(builder: (context, model, child) {
      return const Row(
        children: [
          // if (model.channel?.program.startTime.isNotEmpty ?? false)
          //   Container(
          //     margin: const EdgeInsets.only(left: 4),
          //     child: Text(
          //       model.channel?.program.startTime ?? "",
          //       style: const TextStyle(
          //           fontSize: 9,
          //           color: Colors.white,
          //           fontWeight: FontWeight.w400),
          //     ),
          //   ),
          SizedBox(
            width: 4,
          ),
          Text(
            // model.channel?.program.topic ?? "",
            'model.channel?.program.topic',
            style: TextStyle(
              fontSize: 9,
              color: Colors.white,
              fontWeight: FontWeight.w400,
            ),
          ),
        ],
      );
    });
  }

  Widget get roomDrawerEntry {
    return Builder(builder: (context) {
      return CupertinoButton(
        onPressed: () {
          // if (model.roomModel.channel != null) {
          // Reporter.track(TrackEvent.roomFunctionClick, {
          //   "rid": model.roomModel.channel!.channelId.toInt(),
          //   "room_type": model.roomModel.channel!.roomTypeObj.type,
          //   "channel_type": model.roomModel.channel!.roomLabel,
          //   "use_type": model.roomModel.channel!.usage,
          //   "is_work": model.roomModel.channel!.inProcessOfSchedule,
          //   "owner_uid": model.roomModel.channel!.owner.id.toInt(),
          //   "role": model.roomModel.channel!.owner.role,
          //   "type": "connect_room",
          //   "tool_name": "",
          // });
          // }
          Scaffold.of(context).openEndDrawer();
        },
        minSize: 0,
        padding: EdgeInsets.zero,
        child: Container(
          height: 20,
          decoration: const ShapeDecoration(
            shape: StadiumBorder(),
            color: Color(0x14FFFFFF),
          ),
          margin: const EdgeInsetsDirectional.only(end: 8),
          padding: const EdgeInsets.symmetric(horizontal: 8),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Text(
                // (model.channel?.roomLabelDesc.isNotEmpty ?? false)
                //     ? model.channel!.roomLabelDesc
                //     : T.current!.chat_friends,
                'channel?.roomLabelDesc.isNotEmpty',
                style: TextStyle(
                    fontSize: 10,
                    color: Colors.white,
                    fontWeight: FontWeight.w400),
                // strutStyle: const StrutStyle(height: 1, forceStrutHeight: true),
              ),
              const SizedBox(
                width: 3,
              ),
              JR.img('room_right_arrow_icon.png', width: 10, height: 6),
            ],
          ),
        ),
      );
    });
  }

  // void showRoomPersonalData(
  //     BuildContext context, SimpleChannelUser user) async {
  //   await showModalBottomSheet(
  //       isScrollControlled: true,
  //       shape: const RoundedRectangleBorder(
  //         borderRadius: BorderRadius.only(
  //           topLeft: Radius.circular(24),
  //           topRight: Radius.circular(24),
  //         ),
  //       ),
  //       backgroundColor: Colors.transparent,
  //       context: context,
  //       builder: (context) {
  //         return RoomPersonalDataWidget(
  //           context: context,
  //           channel: model.channel,
  //           user: user,
  //         );
  //       });
  // }

  /// 暂时没用到的  ==============================================================================
}
